package com.lingshi.shopping_order_customer_api.controller;

import com.lingshi.shopping.entity.Orders;
import com.lingshi.shopping.result.BaseResult;
import com.lingshi.shopping.service.OrdersService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * 订单管理
 */
@RestController
@RequestMapping("/user/orders")
public class OrdersController {

    @DubboReference
    private OrdersService ordersService;

    /**
     * 新增订单
     * @param orders 订单对象
     * @return
     */
    @PostMapping("/add")
    public BaseResult add(@RequestHeader("userId") Long userId,@RequestBody Orders orders) {
        orders.setUserId(userId);
        return BaseResult.success(ordersService.add(orders));
    }

    /**
     * 查询用户订单
     * @param userId
     * @param status
     * @return
     */
    @GetMapping("/findUserOrders")
    public BaseResult findUserOrders(@RequestHeader("userId") Long userId,Integer status) {
        return BaseResult.success(ordersService.findUserOrders(userId,status));
    }

    /**
     * 根据id查询订单明细
     * @param id 订单id
     * @return
     */
    @GetMapping("/findById")
    public BaseResult findById(Long id) {
        return BaseResult.success(ordersService.findById(id.toString()));
    }


}
